



import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class SuchServlet
 */
@WebServlet("/SuchServlet")
public class SuchServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	ArtikelSpeicher speicher = ArtikelSpeicher.gibMirDeinenSpeicher();
	private String ergebnis = "";
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SuchServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		
		
		
		
		
		RequestDispatcher index2= request.getRequestDispatcher("index2.jsp");
		index2.include(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String n = request.getParameter("ID");
		String k = request.getParameter("Stich");
		if (n != null){
			
			if (k.length()!=0){
			  ergebnis += speicher.sucheNachBegiff(k);
			  RequestDispatcher fenster= request.getRequestDispatcher("fenster.jsp");
			  request.setAttribute("keyant",ergebnis);
				fenster.include(request, response);
			  
			}
			else  {try{
				  ergebnis += speicher.sucheNachID(Integer.parseInt(n));
				}catch (Exception e){
					request.setAttribute("key", n);
				}
			request.setAttribute("keyant",ergebnis);
			RequestDispatcher fenster= request.getRequestDispatcher("fenster.jsp");
			fenster.include(request, response);
				}
			
		}
		
		request.setAttribute("keyant",ergebnis);
		ergebnis = "";
		
		
	}

}
